Output in JS


JavaScript provides different methods to display output, such as console.log(), alert(), document.write(), and manipulating HTML elements directly.

1. Using console.log()

The console.log() method is used for logging messages to the console. It is a debugging tool available in most web browsers.

console.log("Hello, World!");

2. Using alert()

The alert() method displays an alert box with a specified message and an OK button.

alert("Hello, World!");

3. Using document.write()

The document.write() method writes a string of text to a document stream opened by document.open().

document.write("Hello, World!");

4. Using innerHTML

The innerHTML property sets or returns the HTML content (inner HTML) of an element.

document.getElementById("demo").innerHTML = "Hello, World!";